package com.atguigu.tingshu.album.consumer;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.mapper.AlbumInfoMapper;
import com.google.gson.JsonElement;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class CommentConsumer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    @Autowired
    private AlbumInfoMapper albumInfoMapper;

    @KafkaListener(topics = "commentTopic")
    public void kafkaMq(ConsumerRecord<String, String > record){
        //获取传过来的对象
        JSONObject jsonObject = JSONObject.parseObject(record.value());
        //获取专辑id
        String albumId = jsonObject.getString("albumId");
        //获取声音id
        String trackId = jsonObject.getString("trackId");
        albumInfoMapper.countAlbumComment(albumId);
        albumInfoMapper.countTrackComment(trackId);

    }
}
